//
//  HomeViewController.m
//  NewWeiBo_OC
//
//  Created by 陈竹 on 16/2/21.
//  Copyright © 2016年 陈竹. All rights reserved.
//

#import "HomeViewController.h"
#define CellID @"CZStatusCellID"
@interface HomeViewController ()
@property(nonatomic,strong)NSMutableArray *dataList;
@end

@implementation HomeViewController


#pragma mark - 懒加载
-(NSMutableArray *)dataList{
    if (_dataList==nil) {
        _dataList=[NSMutableArray array];
        [_dataList addObject:@"a"];

    }
    return _dataList;
}



- (void)viewDidLoad {
    //设置刷新的视图
    [self setupRefresh];
    [super viewDidLoad];
    UITableViewCell *cell=[[UITableViewCell alloc]init];
    [self.tabelView registerClass:[cell class] forCellReuseIdentifier:CellID];
    
}
-(void)loadData{
    BOOL isPullUp=self.pullUpView.isAnimating;
    if (!isPullUp) {
        [self.refresh beginRefreshing];
    }
    NSLog(@"刷新");
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableArray *arrayM=[NSMutableArray array];

        [NSThread sleepForTimeInterval:2];
        if (isPullUp) {
            for (int i=0; i<10; i++) {
                NSString *str=[NSString stringWithFormat:@"%@%d-",self.dataList.lastObject,i];
                [arrayM addObject:str];
            }
            [self.dataList addObjectsFromArray:arrayM];
        }else{
            for (int i=10; i>0; i--) {
                NSString *str=[NSString stringWithFormat:@"%@%d+",self.dataList.firstObject,i];
                [arrayM addObject:str];
            }
            [arrayM addObjectsFromArray:self.dataList];
            self.dataList=arrayM;
        }
        
       
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tabelView reloadData];
            [self.pullUpView stopAnimating];
            [self.refresh endRefreshing];
        });
        
        
    });
}

#pragma mark - 数据源和代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.dataList.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    
    cell.textLabel.text=self.dataList[indexPath.row];
    return cell;
}




@end
